using Assets.Scripts.GDK;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class WordInfoAlert : gdk_base_alert_layer
	{
		public RectTransform wordInfoAlertItem;

		private List<WordInfoItemModel> infos;

		public RectTransform scrollRest;

		private int index;

		public RectTransform wordInfoPointsContent;

		public RectTransform wordInfoCtolContent;

		public void OnData(List<string> keys)
		{
			infos = new List<WordInfoItemModel>();
			for (int i = 0; i < keys.Count; i++)
			{
				string key = keys[i];
				GameManager.getWordInfoItem(key, delegate (WordInfoItemModel wordInfoItemModel)
				{
					infos.Add(wordInfoItemModel);
				});
			}
			index = 0;
			showInfoData(index);
			initPoints();
			initCtols();
		}

		public override void OnLoad()
		{
		}

		private void initPoints()
		{
			wordInfoPointsContent.GetComponent<WordInfoAlertPoints>().OnData(infos.Count);
		}

		private void initCtols()
		{
			wordInfoCtolContent.GetComponent<WordInfoAlertCtols>().OnData(delegate (int offset)
			{
				if (index + offset >= 0 && index + offset < infos.Count)
				{
					index += offset;
					UnityEngine.Debug.Log("index=," + index);
					wordInfoPointsContent.GetComponent<WordInfoAlertPoints>().OnShowData(index);
					showInfoData(index);
				}
			});
		}

		private void showInfoData(int index)
		{
			scrollRest.GetComponent<ScrollRect>().StopMovement();
			scrollRest.GetComponent<ScrollRect>().content.localPosition = Vector2.zero;
			WordInfoItemModel wordInfoItemModel = infos[index];
			wordInfoAlertItem.GetComponent<WordInfoAlertItem>().OnData(wordInfoItemModel);
		}
	}
}

